<!-- 店铺选择 -->
<template>
	<view class="">
		<picker @change="bindPickerChange" :value="index" :range="array" v-if="array&&array.length" range-key="name">
			<view class="row-box picker">
				<view class="flex align-items-center">
					<image class="store-logo mr-10" src="/static/images/common/icon-4.png" mode="scaleToFill">
					</image>
					<text class="fs-lg fc-3 fw-9">{{array[index].name}}</text>
				</view>
				<view class="flex align-items-center">
					<text class=""><!-- 切换店铺 --></text>
					<text class="ml-20 fc-9 iconfont ">&#xe687;</text>
				</view>
			</view>
		</picker>
		<view class="row-box picker" v-else>
			<view class="flex align-items-center">
				<image class="store-logo mr-10" src="/static/images/common/icon-4.png" mode="scaleToFill">
				</image>
				<text class="fs-lg fc-3 fw-9">请先绑定门店</text>
			</view>
			<view class="flex align-items-center">
			</view>
		</view>
	</view>
</template>

<script>
	import {
		apiGetStoreList,
		apiChangeStore,
		apiGetStatstics,
		apiOrderList
	} from '@/api/store.js'
	export default {
		data() {
			return {
				array: [],
				userInfo: null,
				index: 0,
			}
		},
		async created() {
			this.userInfo = await this.getUserinfo()
			this.getStoreList()
		},
		methods: {
			async getStoreList() {
				let res = await apiGetStoreList()
				this.array = res
				this.array.forEach((item, index) => {
					if (item.id == this.userInfo.store_id) {
						this.index = index
					}
				})

			},
			async bindPickerChange(e) {
				this.index = e.detail.value
				this.$emit('change', this.array[this.index])
				await apiChangeStore({
					store_id: this.array[this.index].id
				})
				await this.getUserinfo(true)
			},
		},

	}
</script>

<style lang="scss" scoped>
	.store-logo {
		width: 56rpx;
		height: 56rpx;
	}

	.picker {
		height: 100%;
		margin: 0 auto;
	}
</style>